package com.computergames.server.service.reconnect;

import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class ReconnectStrategySelector {
    private final Map<String, ReconnectStrategy> strategyMap = new ConcurrentHashMap<>();

    public ReconnectStrategySelector()
    {
        strategyMap.put("五子棋", new GobangReconnect());
        strategyMap.put("斗地主", new LandlordReconnect());
    }

    public void select(ChannelHandlerContext ctx, String roomType)
    {
        ReconnectStrategy strategy = strategyMap.get(roomType);
        if (strategy == null)
        {
            throw new IllegalArgumentException("No strategy found for message type: " + roomType);
        }
        strategy.reconnect(ctx);
    }
}
